//处理网络请求

import axios from 'axios'

//发送网络请求，统一封装成一个函数。。axios，

// 验证合法性
export async function FetchFuncOld(url, methodType = 'get', data = null) {

  const config = {
    method: methodType,
    headers: {
      "Content-Type": "application/json",
    }
  }
  if (data) {
    config.body = JSON.stringify(data)
  }
  const result = await fetch(url, config) //resolve

  if (methodType == "get")

    if (result.ok) {
      const jsonObj = await result.json();
      return jsonObj.data
    }


  return result


}


export async function FetchFunc(url, methodType = 'get', data = null) {

  const config = {
    url,
    method: methodType,
    headers: {
      "Content-Type": "application/json",
    }
  }
  if (data) {
    config.data = JSON.stringify(data)
  }
  const result = await axios(config) //resolve

  if (methodType == "get")

    if (result.status == 200) {
      const jsonObj = await result.data;
      return jsonObj.data
    }


  return result


}



